/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.quick.newsfeed;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.quick.bean.EventCommentsBean;
import com.quick.bean.EventLikeBean;
import com.quick.bean.ForumEventDetailsBean;
import com.quick.bean.NewsfeedBean;
import com.quick.bean.NfCommentsBean;
import com.quick.bean.Userprofile;
import com.quick.global.GlobalConstants;
import com.quick.utilities.DateUtil;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.vaadin.event.MouseEvents;
import com.vaadin.event.ShortcutAction;
import com.vaadin.event.ShortcutListener;
import com.vaadin.server.ThemeResource;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.*;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.themes.BaseTheme;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

/**
 *
 * @author sonalis
 */
public class ViewNewsfeedDetailsWindow extends Window implements Button.ClickListener {
    
    
    private HorizontalLayout baseLayout;
    private TabSheet tabsheet;    
    private TextArea userNotesTxtArea;
    private int selectedUploadId;
    private NewsfeedBean nfDtls;
    private List<EventLikeBean> eventLikesList;
    private List<NfCommentsBean> nfCommentsList;
    private TextField txtNewComment;
    private String People_who_like_this="People who like this";
    private VerticalLayout verticalForCommentStack;
    private HorizontalLayout likeCommentBtnLayout;
    
    
    
    public ViewNewsfeedDetailsWindow(NewsfeedBean nfDtls) {
        this.nfDtls=nfDtls;
        this.selectedUploadId=selectedUploadId;        
        setModal(true);
        setCaption("Newsfeed details");
        center();        
        setClosable(true);
        setWidth("90%");
        setHeight("90%"); 
        setImmediate(true);
        
        buildBaseStudentLayout();
        addEventDetails();
        //addUserNotes();
        setContent(baseLayout);
        addStyleName("schedule");
        addStyleName("leachBg");
    }
    
    public ViewNewsfeedDetailsWindow(){
    }
    
    //called from forum wrapper click
    public Window doConstructorsWorKForReflection(NewsfeedBean nfDtls,List<EventLikeBean> eventLikesList, List<NfCommentsBean> eventCommentsList)
    {
        this.nfDtls=nfDtls;
        //this.selectedUploadId=selectedUploadId;
        this.nfCommentsList=eventCommentsList;
        this.eventLikesList=eventLikesList;
        setModal(true);
        setCaption("Newsfeed details");
        center();        
        setClosable(true);
        setWidth("80%");
        setHeight("80%"); 
        setImmediate(true);
        
        buildBaseStudentLayout();
        addEventDetails();
        //addUserNotes();
        setContent(baseLayout);
        addStyleName("schedule");
        addStyleName("leachBg");
        return this;
    }
    
    
    //called from dashborad activity feeds
    public Window getEventDetailsWindow(String eventId)
    {
        getEventDetailsById(eventId);        
       
        setModal(true);
        setCaption("Newsfeed details");
        center();        
        setClosable(true);
        setWidth("80%");
        setHeight("80%"); 
        setImmediate(true);
        
        
        buildBaseStudentLayout();
        addEventDetails();
        //addUserNotes();
        setContent(baseLayout);
        addStyleName("schedule");
        addStyleName("leachBg");
        return this;
    }
    
   /*  public ViewTopicDetailsWindow(StudentView studentView, List<Userprofile> studentList) {
            
        setModal(true);       
        setCaption("Welcome to Edit Student");
        setContent(baseLayout);
        center();        
        setClosable(false);
        setWidth("70%");
        setHeight("100%");
        buildBaseStudentLayout();
    } */
    
     private void buildBaseStudentLayout(){
              
       baseLayout = new HorizontalLayout();
       baseLayout.setImmediate(true);
       baseLayout.setSpacing(false);   
       baseLayout.setMargin(false);
       baseLayout.setWidth("100%");
       baseLayout.setHeight("100%");
    }

    @Override
    public void buttonClick(ClickEvent event) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    private void addEventDetails() 
    {
        getEventImage();
        getEventDetails();
//        showLikeAndCommentsForm();
        fetchNewsfeedLikesAndComments(nfDtls);
        showFullCommentsStack();
        
        //baseLayout.setExpandRatio(tabsheetLayout,2);
    }

    private void getEventImage() 
    {

        String str="<!DOCTYPE html>\n" +
"<html>\n" +
"  <body>\n" +
"    <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->\n" +
"<iframe id=\"player\" type=\"text/html\" width=\"425\" height=\"325\"\n" +
"  src=\"https://www.youtube.com/embed/"+nfDtls.getNfUrl()+"?enablejsapi=1&origin=https://example.com\"\n" +
"  frameborder=\"0\"></iframe>"+
"\n" +
"    <script>\n" +
"      // 2. This code loads the IFrame Player API code asynchronously.\n" +
"      var tag = document.createElement('script');\n" +
"\n" +
"      tag.src = \"https://www.youtube.com/iframe_api\";\n" +
"      var firstScriptTag = document.getElementsByTagName('script')[0];\n" +
"      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n" +
"\n" +
"      // 3. This function creates an <iframe> (and YouTube player)\n" +
"      //    after the API code downloads.\n" +
"      var player;\n" +
"      function onYouTubeIframeAPIReady() {\n" +
"        player = new YT.Player('player', {\n" +
"          height: '325',\n" +
"          width: '425',\n" +
"          videoId: '"+nfDtls.getNfUrl()+"',\n" +
"          events: {\n" +
"            'onReady': onPlayerReady,\n" +
"            'onStateChange': onPlayerStateChange\n" +
"          }\n" +
"        });\n" +
"      }\n" +
"\n" +
"      // 4. The API will call this function when the video player is ready.\n" +
"      function onPlayerReady(event) {\n" +
"        event.target.playVideo();\n" +
"      }\n" +
"\n" +
"      // 5. The API calls this function when the player's state changes.\n" +
"      //    The function indicates that when playing a video (state=1),\n" +
"      //    the player should play for six seconds and then stop.\n" +
"      var done = false;\n" +
"      function onPlayerStateChange(event) {\n" +
"        if (event.data == YT.PlayerState.PLAYING && !done) {\n" +
"          setTimeout(stopVideo, 6000);\n" +
"          done = true;\n" +
"        }\n" +
"      }\n" +
"      function stopVideo() {\n" +
"        player.stopVideo();\n" +
"      }\n" +
"    </script>\n" +
"  </body>\n" +
"</html>";
        
        Label video = new Label(str, ContentMode.HTML);
        
        
        
  
        VerticalLayout imageLayout = new VerticalLayout();
        imageLayout.setMargin(true);
        imageLayout.setSizeFull();
        imageLayout.addComponent(video);
        imageLayout.setComponentAlignment(video,Alignment.MIDDLE_CENTER);
        imageLayout.addStyleName("leachBg");
        
        baseLayout.addComponent(imageLayout);
        baseLayout.setExpandRatio(imageLayout,2.75f);
        baseLayout.setComponentAlignment(imageLayout,Alignment.MIDDLE_CENTER);
        
    }

    VerticalLayout v;
    private Component getEventDetails() 
    {
        v = new VerticalLayout();
        v.setImmediate(true);
        v.setSizeFull();
        v.setSpacing(true);
        //v.setMargin(new MarginInfo(true, false, true, false));
        v.setMargin(false);
        v.setHeight("100%");
        v.addStyleName("whiteBg");
        
        HorizontalLayout photoAndEventDtls = new HorizontalLayout();

        photoAndEventDtls.addStyleName("leachBottomBorder");
        
        photoAndEventDtls.setMargin(false);
        photoAndEventDtls.setSpacing(false);
        photoAndEventDtls.setWidth("100%");
        photoAndEventDtls.setHeight("100%");
        Image userImage = new Image(null, new ThemeResource("img/profile-pic.png"));

        userImage.setWidth("30px");
        userImage.setWidth("30px");
        photoAndEventDtls.addComponent(userImage);
        photoAndEventDtls.setExpandRatio(userImage, 0.5f);
        photoAndEventDtls.setComponentAlignment(userImage, Alignment.MIDDLE_LEFT);
                                    
        String cap = "<div style='color:#3b5998;display:inline-block;'> <b>" + nfDtls.getNfOwner() + "</b></div>" + "<div style='color:grey;font-size:13px;display:inline-block;'>&nbsp; shared </div> <div style='color:#3b5998;display:inline-block;'>"
                + nfDtls.getNfDesc()+"</div><br><div style='color:grey;font-size:11px;display:inline-block;'>" +DateUtil.getTimeIntervalOfTheActivity(nfDtls.getNfDate()) + "</div>";
        Label eventIntro = new Label(cap, ContentMode.HTML);
        eventIntro.setWidth("100%");
        photoAndEventDtls.addComponent(eventIntro);
        photoAndEventDtls.setExpandRatio(eventIntro, 3);
        photoAndEventDtls.setComponentAlignment(eventIntro, Alignment.MIDDLE_LEFT);
            
        Label eventDesc = new Label(nfDtls.getNfBody());
        eventDesc.setWidth("100%");
        eventDesc.setHeight("100%");
        
        v.addComponent(photoAndEventDtls);
        //v.setExpandRatio(photoAndEventDtls, 1);
        v.addComponent(eventDesc);
        //v.setExpandRatio(eventDesc, 3);
        
        Table forumTable=new Table();
        forumTable.addContainerProperty(GlobalConstants.emptyString, VerticalLayout.class, null);
        forumTable.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
        forumTable.addStyleName("plain");
        forumTable.addStyleName("borderless");
        forumTable.setHeight("99%");
        forumTable.setWidth("100%");
        forumTable.setSortEnabled(false);
        forumTable.addItem(new Object[]{v},forumTable.size()+1);
        
        VerticalLayout tableVertical = new VerticalLayout();
        tableVertical.setSizeFull();
        tableVertical.addStyleName("whiteBg");
        tableVertical.addComponent(forumTable);
        
        baseLayout.addComponent(tableVertical);
        baseLayout.setExpandRatio(tableVertical,2.25f);
        return v;
    }
    
    private void showLikeAndCommentsForm() {
        likeCommentBtnLayout = new HorizontalLayout();
        Embedded likeImage ;
        Embedded commentImage;
        
        likeCommentBtnLayout.setSpacing(false);
        likeCommentBtnLayout.setWidth("50%");
        //likeCommentLayout.setMargin(true);
        //likeCommentBtnLayout.addStyleName("backgroundColor");

        //likeCommentBtnLayout.setWidth("60%");
        Button likeBtn = new Button("Like");
        ///Button commentBtn = new Button("Comment");

        likeBtn.addStyleName(BaseTheme.BUTTON_LINK);
        likeBtn.addClickListener(new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                sendLike();
                fetchNewsfeedLikesAndComments(nfDtls);
//                fetchEventLikesAndComments();
//                               
//                if(verticalForCommentStack!=null)
                  v.removeComponent(verticalForCommentStack);
                  v.removeComponent(likeCommentBtnLayout);
                showLikeAndCommentsForm();
                showFullCommentsStack();
            }
        });
//        commentBtn.addStyleName(BaseTheme.BUTTON_LINK);
//        commentBtn.addClickListener(new Button.ClickListener() {
//
//            @Override
//            public void buttonClick(ClickEvent event) {  
//                //showFullCommentsStack();
//            }
//        });
//        likeBtn.addStyleName("link");
//        commentBtn.addStyleName("link");
        likeCommentBtnLayout.addComponent(likeBtn);
        //likeCommentBtnLayout.addComponent(commentBtn);
        likeImage =  new Embedded(null,new ThemeResource("./img/like-icon.jpg"));
        likeImage.setHeight("22px");
        likeImage.setWidth("22px");
        likeImage.addClickListener(new com.vaadin.event.MouseEvents.ClickListener() {

            @Override
            public void click(MouseEvents.ClickEvent event) {
                showLikesWindow();
            }
     });
        likeCommentBtnLayout.addComponent(likeImage);
        likeCommentBtnLayout.addComponent(new Label(GlobalConstants.emptyString + eventLikesList.size() ));
        commentImage =  new Embedded(null,new ThemeResource("./img/comments-icon.jpg"));
        commentImage.setHeight("22px");
        commentImage.setWidth("22px");
        likeCommentBtnLayout.addComponent(commentImage);
        likeCommentBtnLayout.addComponent(new Label(GlobalConstants.emptyString + nfCommentsList.size() ));
//        Label eventTime=new Label( DateUtil.getTimeIntervalOfTheActivity(eventDtls.getEventDate()));
//        eventTime.addStyleName("lightGrayColorAndSmallFont");
//        likeCommentBtnLayout.addComponent(eventTime);
        v.addComponent(likeCommentBtnLayout);
        //v.setExpandRatio(likeCommentBtnLayout, 1);
    }
    
    private void showFullCommentsStack() 
    {
        verticalForCommentStack = new VerticalLayout();
        verticalForCommentStack.setMargin(false);
        verticalForCommentStack.setSpacing(true);
        verticalForCommentStack.setWidth("100%");
        verticalForCommentStack.setHeight("100%");
        verticalForCommentStack.addStyleName("backgroundColor");
        HorizontalLayout fullCommentsLayout;
        for (NfCommentsBean comment : nfCommentsList) {
            fullCommentsLayout = new HorizontalLayout();
            fullCommentsLayout.addStyleName("whiteBottomBorder");
            fullCommentsLayout.setMargin(false);
            fullCommentsLayout.setSpacing(true);
            fullCommentsLayout.setWidth("100%");
            fullCommentsLayout.setHeight("100%");
            Image userImage = new Image(null, new ThemeResource("img/profile-pic.png"));

            userImage.setWidth("30px");
            userImage.setWidth("30px");
            fullCommentsLayout.addComponent(userImage);
            fullCommentsLayout.setExpandRatio(userImage, 0.5f);
            fullCommentsLayout.setComponentAlignment(userImage, Alignment.TOP_LEFT);
            Label lblComment = new Label("<b>" + comment.getName() + ": </b>" + comment.getNfBody(), ContentMode.HTML);
            fullCommentsLayout.addComponent(lblComment);
            fullCommentsLayout.setExpandRatio(lblComment, 4);
            fullCommentsLayout.setComponentAlignment(lblComment, Alignment.MIDDLE_LEFT);
            
            Label lblCommentTime=new Label(DateUtil.getTimeIntervalOfTheActivity(comment.getCommentTime()));
            lblCommentTime.addStyleName("lightGrayColorAndSmallFont");
            fullCommentsLayout.addComponent(lblCommentTime);
            fullCommentsLayout.setExpandRatio(lblCommentTime, 1.25f);
            fullCommentsLayout.setComponentAlignment(lblCommentTime, Alignment.MIDDLE_RIGHT);

            verticalForCommentStack.addComponent(fullCommentsLayout);

        }
        fullCommentsLayout = new HorizontalLayout();
        fullCommentsLayout.addStyleName("whiteBottomBorder");
        fullCommentsLayout.setMargin(false);
        fullCommentsLayout.setSpacing(false);
        fullCommentsLayout.setWidth("100%");
        fullCommentsLayout.setHeight("100%");

        Image userImage = new Image(null, new ThemeResource("img/profile-pic.png"));
        userImage.setWidth("30px");
        userImage.setWidth("30px");
        txtNewComment = new TextField();
        txtNewComment.setWidth("100%");
        txtNewComment.setImmediate(true);
        txtNewComment.setInputPrompt("Write a comment...");
        txtNewComment.addShortcutListener(new ShortcutListener("Shortcut Name", ShortcutAction.KeyCode.ENTER, null) {

            @Override
            public void handleAction(Object sender, Object target) {
                if (txtNewComment.getValue() != null && !txtNewComment.getValue().equals(GlobalConstants.emptyString)) {
                    if(txtNewComment.getValue().length()>1000)
                    {
                        Notification.show("Comment cannot be more than 1000 characters.", Notification.Type.WARNING_MESSAGE);
                    }
                    else
                    {
                        saveComment(txtNewComment.getValue());
                        v.removeComponent(verticalForCommentStack);
                        v.removeComponent(likeCommentBtnLayout);
                        fetchNewsfeedLikesAndComments(nfDtls);
                        showLikeAndCommentsForm();
                        showFullCommentsStack();
                    }
                }
            }
        });

        fullCommentsLayout.addComponent(userImage);
        fullCommentsLayout.setExpandRatio(userImage, 0.5f);
        fullCommentsLayout.setComponentAlignment(userImage, Alignment.TOP_LEFT);
        fullCommentsLayout.addComponent(txtNewComment);
        fullCommentsLayout.setExpandRatio(txtNewComment, 4);
        fullCommentsLayout.setComponentAlignment(txtNewComment, Alignment.MIDDLE_LEFT);
        verticalForCommentStack.addComponent(fullCommentsLayout);
        
        v.addComponent(verticalForCommentStack);
        //v.setExpandRatio(verticalForCommentStack, 5);
    }
    
    private void showLikesWindow() {

        VerticalLayout verticalForLikes = new VerticalLayout();
        verticalForLikes.setMargin(false);
        verticalForLikes.setSpacing(true);
        verticalForLikes.setWidth("100%");
        verticalForLikes.addStyleName("backgroundColor");
        HorizontalLayout likeNamesLayout;
        for (EventLikeBean like : eventLikesList) {
            likeNamesLayout = new HorizontalLayout();
            likeNamesLayout.addStyleName("whiteBottomBorder");
            likeNamesLayout.setMargin(false);
            likeNamesLayout.setSpacing(false);
            likeNamesLayout.setWidth("100%");
            likeNamesLayout.setHeight("100%");
            Image userImage = new Image(null, new ThemeResource("img/profile-pic.png"));

            userImage.setWidth("30px");
            userImage.setWidth("30px");
            likeNamesLayout.addComponent(userImage);
            likeNamesLayout.setExpandRatio(userImage, 0.5f);
            likeNamesLayout.setComponentAlignment(userImage, Alignment.TOP_LEFT);
            Label lblComment = new Label("<b>" + like.getName() + "</b>", ContentMode.HTML);
            likeNamesLayout.addComponent(lblComment);
            likeNamesLayout.setExpandRatio(lblComment, 1);
            likeNamesLayout.setComponentAlignment(lblComment, Alignment.MIDDLE_LEFT);

            Label lblCommentTime = new Label(DateUtil.getTimeIntervalOfTheActivity(like.getLikeTime()));
            lblCommentTime.addStyleName("lightGrayColorAndSmallFont");
            likeNamesLayout.addComponent(lblCommentTime);
            likeNamesLayout.setExpandRatio(lblCommentTime, 1);
            likeNamesLayout.setComponentAlignment(lblCommentTime, Alignment.MIDDLE_RIGHT);

            verticalForLikes.addComponent(likeNamesLayout);

        }

        Window w = new Window(People_who_like_this);
        w.center();
        w.setWidth("35%");
        w.setHeight("40%");
        w.setContent(verticalForLikes);
        getUI().getCurrent().addWindow(w);
    }
    
    private void sendLike() {
        try {
            Userprofile profile = ((Userprofile) getSession().getAttribute(GlobalConstants.CurrentUserProfile));
            JSONObject input = new JSONObject();
            input.put("event_id", nfDtls.getNfId());
            input.put("username", profile.getUsername());
            input.put("name", profile.getName());

            Client client = Client.create();
            WebResource webResource = client.resource(GlobalConstants.getProperty(GlobalConstants.SAVE_EVENT_LIKE));
            ClientResponse response = webResource.type(GlobalConstants.application_json).post(ClientResponse.class, input);

            /*
             * if (response.getStatus() != 201) { throw new
             * RuntimeException("Failed : HTTP error code : " +
             * response.getStatus()); }
             */

            String output = response.getEntity(String.class);
        } catch (JSONException ex) {
            ex.printStackTrace();
        }

    }
    
    private void getEventDetailsById(String eventId) {
        try 
        {
            Client client = Client.create();
            
            WebResource webResource = client.resource(GlobalConstants.getProperty(GlobalConstants.GET_FORUM_EVENT_BY_ID));
            
            JSONObject inputJson = new JSONObject();
            
            inputJson.put("eventId",eventId);
             
            ClientResponse response = webResource.type(GlobalConstants.application_json).post(ClientResponse.class, inputJson);
            
            JSONObject outNObject = null;
            String output = response.getEntity(String.class);
            outNObject = new JSONObject(output);

            java.lang.reflect.Type listType = new TypeToken<ArrayList<ForumEventDetailsBean>>() {
            }.getType();
    
            Gson gson=  new GsonBuilder().setDateFormat(GlobalConstants.gsonTimeFormat).create();
            
            List <NewsfeedBean> forumEventDetailsList=gson.fromJson(outNObject.getString(GlobalConstants.eventDetailsList), listType);
            this.nfDtls=forumEventDetailsList.get(0);
            
           Type listType1 = new TypeToken<ArrayList<EventLikeBean>>() {
            }.getType();
            
             Gson eventLikesGson = new GsonBuilder().setDateFormat(GlobalConstants.gsonTimeFormat).create();       
            eventLikesList = eventLikesGson.fromJson(outNObject.getString(GlobalConstants.eventLikes), listType1);
            
            Type listType2 = new TypeToken<ArrayList<EventCommentsBean>>() {
            }.getType();
            
             Gson eventCommentsGson = new GsonBuilder().setDateFormat(GlobalConstants.gsonTimeFormat).create();       
            nfCommentsList = eventCommentsGson.fromJson(outNObject.getString(GlobalConstants.eventComments), listType2);
            
        } catch (JSONException ex) 
        {
            ex.printStackTrace();
        }
    }
    
    private void fetchNewsfeedLikesAndComments(NewsfeedBean nfDtls) {
        try {
            JSONObject input = new JSONObject();
            input.put("nf_id", nfDtls.getNfId());

            Client client = Client.create();
            WebResource webResource = client.resource(GlobalConstants.getProperty(GlobalConstants.FETCH_NF_LIKES_N_COMMENTS_BY_ID));
            ClientResponse response = webResource.type(GlobalConstants.application_json).post(ClientResponse.class, input);

            /*
             * if (response.getStatus() != 201) { throw new
             * RuntimeException("Failed : HTTP error code : " +
             * response.getStatus()); }
             */

            JSONObject outNObject = null;
            String output = response.getEntity(String.class);
            outNObject = new JSONObject(output);

           /*   Type listType1 = new TypeToken<ArrayList<EventLikeBean>>() {
            }.getType();
            
             Gson eventLikesGson = new GsonBuilder().setDateFormat(GlobalConstants.gsonTimeFormat).create();       
            eventLikesList = eventLikesGson.fromJson(outNObject.getString(GlobalConstants.eventLikes), listType1); */
            
            Type listType2 = new TypeToken<ArrayList<NfCommentsBean>>() {
            }.getType();
            
             Gson eventCommentsGson = new GsonBuilder().setDateFormat(GlobalConstants.gsonTimeFormat).create();       
            nfCommentsList = eventCommentsGson.fromJson(outNObject.getString(GlobalConstants.nfComments), listType2);
            
            //System.out.println("eve"+eventLikesList);
            
        } catch (JSONException ex) {
            ex.printStackTrace();
        }

    }
    
    private void saveComment(String value) 
    {
          try {
            Userprofile profile = ((Userprofile) getSession().getAttribute(GlobalConstants.CurrentUserProfile));
            JSONObject input = new JSONObject();
            input.put("event_id", nfDtls.getNfId());
            input.put("event_desc", nfDtls.getNfDesc());
            input.put("username", profile.getUsername());
            input.put("name", profile.getName());
            input.put("comment", value);

            Client client = Client.create();
            WebResource webResource = client.resource(GlobalConstants.getProperty(GlobalConstants.SAVE_EVENT_COMMENT));
            ClientResponse response = webResource.type(GlobalConstants.application_json).post(ClientResponse.class, input);

            /*
             * if (response.getStatus() != 201) { throw new
             * RuntimeException("Failed : HTTP error code : " +
             * response.getStatus()); }
             */

            String output = response.getEntity(String.class);
        } catch (JSONException ex) {
            ex.printStackTrace();
        }
          
   }
    
}
